import requests

# 基础初始化设置
base_url = "http://localhost:11434/api"
headers = {
    "Content-Type": "application/json"
}
def generate_completion(prompt, model="wangshenzhi/llama3-8b-chinese-chat-ollama-q4:latest"):
    url = f"{base_url}/generate"
    data = {
        "model": model,
        "prompt": prompt,
        "stream": False
    }
    response = requests.post(url, headers=headers, json=data)
    return response.json().get('response', '')



# 示例调用
completion = generate_completion("你好")
print("生成文本补全:", completion)
